home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-10-25 | 23.3 KB | 559 lines | [TEXT/MPS ] |
- {[a-,body+,h-,o=100,r+,rec+,t=4,u+,#+,j=20/57/1$,n-]}
- { UPrinting.p }
- { Copyright © 1986-1990 by Apple Computer Inc. All rights reserved. }
-
- {$IFC UNDEFINED UsingIncludes}
- {$SETC UsingIncludes := FALSE}
- {$ENDC}
-
- {$IFC NOT UsingIncludes}
- UNIT UPrinting;
-
- INTERFACE
- {$ENDC}
-
- {$IFC UNDEFINED __UPrinting__}
- {$SETC __UPrinting__ := FALSE}
- {$ENDC}
-
- {$IFC NOT __UPrinting__}
- {$SETC __UPrinting__ := TRUE}
-
- { • Required for this unit's interface. Auto-Include them }
- {$SETC UPrintingIncludes := UsingIncludes}
- {$SETC UsingIncludes := TRUE}
- {$I+}
- {$IFC UNDEFINED __UMacApp__} {$I UMacApp.p} {$ENDC}
-
- {$IFC UNDEFINED UsingDialogs} {$I Dialogs.p} {$ENDC}
- {$IFC NOT qNeedsROM128K}
- {$IFC UNDEFINED UsingPrinting} {$I Printing.p} {$ENDC}
- {$ELSEC}
- {$IFC UNDEFINED UsingPrintTraps} {$I PrintTraps.p} {$ENDC}
- {$ENDC}
- {$SETC UsingIncludes := UPrintingIncludes}
-
- CONST
-
- { Command constants }
- cChangePrinterStyle = 192; { Command arising from user's making changes
- in Page Setup... dialog }
- cShowBreaks = 201; { “Show Page Breaks” command }
-
- { Printing-related command numbers which apply only when a view with a non-null PrintHandler
- is in the target chain }
-
- { Dialogs }
- phSpoolPrintDialog = 257; { the dialog shown when printing a file (a
- misnomer - not just when spooled) }
- phFinderPrintDialog = 258; { the dialog shown when doing Finder
- Printing; differs from prev. by addition
- of a 'Cancel All Printing' button }
-
- { Alerts }
- phNoPages = 251; { The “no pages within requested range”
- alert }
-
- { Dialogs }
- phWhichDoc = 261; { The “Preparing to print <docname>” dialog
- used during Finder printing }
-
- { Miscellaneous }
- kUsualPages = MAXINT; { For methods that take a “pageNumber”
- argument, this value indicates a request
- for a general setting rather than a
- setting customized to one particular page
- }
-
- kNeverInitialized = MAXINT; { Pseudo-value for fPrinterDev field of
- TStdPrintHandler; used to trigger an
- initial PrinterChanged call }
-
- kPrintDriverName = $E000; { STR resource in System file which contains
- name of the current print driver }
-
- TYPE
-
- PageAreas = RECORD
- thePaper: Rect; { physical page }
- theInk: Rect; { printable page }
- theMargins: Rect; { top-left positive; bottom-right negative }
- theInterior: Rect; { rect into which view-subset is projected }
- END;
-
- TStdPrintHandler = OBJECT (TPrintHandler) { Actually Implements all the features that
- were stubbed out in its ancestor. Basic
- flow of control at print time: Print,
- CheckPrinter, For each page(
- FocusOnBorder, DrawPageInterior,
- FocusOnBorder, AdornPage) are called. }
- fPageAreas: PageAreas; { metrics for printing }
-
- fPrintExtent: VRect; { the part of the view's extent that is to
- be printed by this print handler. The
- default is the entire extent, but it can
- be changed with the method SetAreaToPrint.
- }
-
- fFixedSizePages: ARRAY [VHSelect] OF BOOLEAN;
- { Indicates whether pages are fixed size
- horzontally and vertically. }
-
- fHPrint: Handle; { actually of THPrint, a MacPrint type. The
- Print Record is 120 bytes long, and may be
- shared among all PrintHandlers in a
- document or may be unique to each
- PrintHandler, depending on the flag
- TDocument.fSharePrintInfo }
-
- fPageStrips: Point; { For printing a view which will take more
- than one page to print, the view is
- thought of as being divided up by vertical
- and horizontal lines ('page breaks') into
- a checkerboard of 'pages'. A vertical
- column, one page wide, of such pages is
- called a 'vertical page strip', while a
- horizontal row, one page high, of such
- pages is called a 'horizontal page strip'.
- The number of vertical page strips is
- represented by fPageStrips.v, and the
- number of horizontal page strips is
- represented by fPageStrips.h In a typical
- Word Processor application, there is only
- one vertical strip of pages, but many
- horizontal 'strips', each one only one
- page wide. In a graphical application,
- there may be many vertical as well as
- horizontal strips of pages. fPageStrips is
- recomputed by method CalcPageStrips. }
-
- fStartPage: INTEGER; { the page number for the topleftmost corner
- of the view. Normally 1, but can be set to
- any positive value }
-
- fPrinterDev: INTEGER; { MacPrint's device number for printer; use
- this at Print time for getting font
- metrics in device coordinates }
-
- fLastCheckedPrinter: LONGINT; { The time that the user's chosen Printer
- and my own idea of printer metrics were
- last known to be in harmony }
-
- fLastPrinterName: StringHandle; { The name of the current printer driver, at
- fLastCheckedPrinter. }
-
- fPageDirection: VHSelect; { Determines how page numbers are to advance
- in a large view which is more than one
- page wide and more than one page high; v
- means page 2 is BELOW page 1; h means it's
- to its RIGHT. Irrelevant if the view is
- only one page wide or only one page high }
-
- fShowBreaks: BOOLEAN; { TRUE iff page breaks should be displayed
- at the moment }
-
- fFinderSetup: BOOLEAN; { whether, during Finder Printing, the 'Page
- Setup' dialog should be presented to the
- user }
-
- fFinderJobDialog: BOOLEAN; { whether, during Finder Printing, the Print
- Job dialog should be presented to the user
- (making it seem like “Print...”) or not
- (making it seem like “Print One”) }
-
- fSquareDots: BOOLEAN; { if TRUE, then in the initial instance, use
- 72 x 72 resolution by default on
- ImageWriter; if FALSE, then full 80 x 72
- is used. This flag has no significance if
- the default printer at the time of
- creation of the printHandler is not an
- ImageWriter }
- fMinimalMargins: BOOLEAN; { If TRUE, page margins are maintained such
- that exactly the complete printable area
- of the page is used. }
-
- fLastStrip: Point; { The last strip printed. }
-
- fLastBreak: VPoint; { The coordinates of the last page break. }
-
- fViewedRect: VRect; { The part of the view shown on the
- "current" page. Set by SetPage. }
-
- fMarginRes: Point; { Used when computing margins }
-
- fPrintDialog: DialogPtr; { Used for all printing-related dialogs. ???
- (shouldn't this really be a view (or
- TDialogView if using UDialog) }
- fPPrPort: TPPrPort; { Printer Port in use during printing }
- { Initialization/Termination }
- PROCEDURE TStdPrintHandler.IStdPrintHandler(itsDocument: TDocument;
- itsView: TView;
- itsSquareDots, itsHFixedSize,
- itsVFixedSize: BOOLEAN);
- { Initializes the printHandler and installs it in the view; if 'itsSquareDots' is
- TRUE, then a default print record for the ImageWriter world will use square dots
- ('tall adjusted') rather than rectangular ones; this sacrifices a bit of resolution
- but ensures that graphics will appear undistorted on the printed page }
-
- PROCEDURE TStdPrintHandler.Free; OVERRIDE;
- { If relevant, frees the PrintInfo record and does other cleanup before freeing SELF
- }
-
- { Page Strips }
-
- PROCEDURE TStdPrintHandler.CalcPageStrips(VAR pageStrips: Point); OVERRIDE;
- { Recalculate the number of strips of pages in each dimension }
-
- PROCEDURE TStdPrintHandler.CalcViewPerPage(VAR amtPerPage: VPoint); OVERRIDE;
- { Decide how much view (h and v) normally gets mapped into page interiors }
-
- FUNCTION TStdPrintHandler.BreakFollowing(vhs: VHSelect;
- prevBreak: VCoordinate;
- VAR automatic: BOOLEAN): VCoordinate;
- OVERRIDE;
- { Returns the location of the page break which follows the page break located at
- 'prevBreak', in direction vhs; returns automatic = TRUE if the page-break is
- thought of as an 'automatic' rather than a 'manual' (user-specified) one. Note that
- page-breaks in dimension 'v' are drawn as vertical lines, those in dimension 'h' as
- horizontal lines. Generic support at present is only provided for 'automatic' page
- breaks; the 'automatic' parameter in BreakFollowing is a hook to allow clients to
- support manual page breaks as well }
-
- PROCEDURE TStdPrintHandler.EachBreak(vhs: VHSelect;
- includeLast: BOOLEAN;
- FUNCTION
- DoToBreak(loc: VCoordinate;
- automatic: BOOLEAN): BOOLEAN);
- { Iterates through all page-breaks in the dimension given by vhs, or until DoToBreak
- returns true; the trailing edge of the view (i.e., right or bottom edge) is given
- as the final break if 'includeLast' is TRUE. The function 'DoToBreak' is called
- once for each page break in the chosen dimension }
-
- PROCEDURE TStdPrintHandler.GetBreakCoord(vhs: VHSelect;
- whichBreak: INTEGER;
- VAR loc: VCoordinate);
- { Returns, in 'loc', the coordinate of the 'whichBreak-th' page break in dimension
- vhs. For example, GetBreakCoord(v, 5, loc) will return, in 'loc', the horizontal
- coordinate of the vertical line (page-break) which marks the boundary the area of
- the view which will be mapped into the 4th vertical strip of pages and the area of
- the view which will be mapped into the 5th vertical strip of pages }
-
- FUNCTION TStdPrintHandler.PageToStrip(pageNumber: INTEGER): Point;
- { Returns the horizontal and vertical strip for the given page. }
-
- FUNCTION TStdPrintHandler.StripToPage(hStrip, vStrip: INTEGER): INTEGER;
- { Returns the page number for the given page strip. }
-
- FUNCTION TStdPrintHandler.PointToPageStrip(pointInView: VPoint): Point;
- { Returns the page strip for a given point in view space. }
-
- { General Utility }
-
- PROCEDURE TStdPrintHandler.GetDocName(VAR docName: Str255);
- { Returns the name of the document being printed, for use in the print dialog. }
-
- PROCEDURE TStdPrintHandler.DoInMacPrint(PROCEDURE WhatToDo);
- { If printing code is available, open the Print Driver, then call procedure
- “WhatToDo”, then close the Print Driver. If printing code not available, does
- nothing }
-
- PROCEDURE TStdPrintHandler.OpenPrintShop;
- { Attempts to open the print shop by calling PrOpen. Signals failure if an error
- occurs. Called from DoInMacPrint. }
-
- PROCEDURE TStdPrintHandler.ClosePrintShop;
- { Closes the print shop by calling PrClose. DOES NOT signal failure if an error
- occurs, only reports it to the debug window. }
-
- FUNCTION TStdPrintHandler.MaxPageNumber: INTEGER; OVERRIDE;
- { Returns the highest page number which would be printed if the user requested that
- “all pages” be printed }
-
- PROCEDURE TStdPrintHandler.AdornPage;
- { Draw things on page # 'aPageNumber' which do not arise from the View but rather
- from page considerations; examples: Headers and Footers; page numbers; frames drawn
- around inset text; row and column headers for spreadsheets. }
-
- PROCEDURE TStdPrintHandler.ChooseSpoolFile(VAR spoolFileName: Str255;
- VAR spoolVRefNum: INTEGER;
- VAR pagesPerSubjob: INTEGER);
- { Select the filename and volume to use for spooling; default chooses empty string on
- vol 0, which results in MacPrint's automatically choosing the local Boot volume }
-
- PROCEDURE TStdPrintHandler.DrawPageInterior;
- { Make the QuickDraw calls which will result in the 'Interior' of page #
- 'aPageNumber' being drawn. The 'Interior' is those things on the page which arise
- from drawing the View associated with the PrintHandler }
-
- PROCEDURE TStdPrintHandler.FocusOnBorder;
- { Set up GrafPort, clipping, etc., prior to calling AdornPage }
-
- PROCEDURE TStdPrintHandler.FocusOnInterior; OVERRIDE;
- { Set up the GrafPort, clipping, etc., prior to calling DrawPageInterior }
-
- PROCEDURE TStdPrintHandler.LocatePageInterior(pageNumber: INTEGER;
- VAR loc: Point); OVERRIDE;
- { Determine where to locate the top-left corner of the Interior of the given page
- nuamber }
-
- FUNCTION TStdPrintHandler.OneSubJob(subjobFirstPage, subjobLastPage: INTEGER;
- justSpool: BOOLEAN;
- partialJob: BOOLEAN;
- VAR ranOutOfSpace: BOOLEAN;
- VAR lastPageTried: INTEGER;
- VAR proceed: BOOLEAN): TCommand;
- { Processes one subjob for printing. Where appropriate, a print job is divided
- automatically into one or more 'subjobs', so that a long document can be printed
- even if there is very limited spool space available on the disk. This is a
- generalization of the 'spool-a-page/print-a-page' technique. TStdPrintHandler will
- use a subjob size as large as can be handled by current conditions, and will only
- fall back to more subjobs, each of smaller size, if it experiences problems running
- with a larger subjob size }
-
- FUNCTION TStdPrintHandler.Print(itsCmdNumber: CmdNumber;
- VAR proceed: BOOLEAN): TCommand; OVERRIDE;
- { Carries out printing for the print handler. }
-
- PROCEDURE TStdPrintHandler.PrintPage(aPageNumber: INTEGER);
- { Print the indicated page }
-
- PROCEDURE TStdPrintHandler.SetPage(aPageNumber: INTEGER);
- { Forwards to TView.DoSetInterior and TView.DoSetPageOffset }
-
- PROCEDURE TStdPrintHandler.SetPageInterior(pageNumber: INTEGER); OVERRIDE;
- { Responsible for installing the correct values into fPageAreas.theInterior,
- representing the 'interior' of the page in View coordinates }
-
- PROCEDURE TStdPrintHandler.SetPageOffset(coord: VPoint); OVERRIDE;
- { Given the view-coordinate of the top-left-most point of the view which is mapped
- into the interior of this page, calculate and set the offset for the print code. }
-
- { Formatting for printing and other Setup methods }
-
- PROCEDURE TStdPrintHandler.CheckPrinter; OVERRIDE;
- { Check to see if user has changed printer specifications; if so, react }
-
- PROCEDURE TStdPrintHandler.InstallMargins(newMargins: Rect;
- areMinimalMargins: BOOLEAN);
- { Install the (possibly new) margins specified; if 'areMinimalMargins' is TRUE, then
- the minimal-margins scheme is used; in this scheme, margins are always maintained
- at exactly the size necessary to have the page Interior coincide exactly with the
- printable area of the page }
-
- PROCEDURE TStdPrintHandler.PrinterChanged; OVERRIDE;
- { After printer specifications have changed, absorb the new metrics and reformat the
- view if necessary }
-
- PROCEDURE TStdPrintHandler.RedoPageBreaks; OVERRIDE;
- { Recalculate the page breaks }
-
- PROCEDURE TStdPrintHandler.Reset; OVERRIDE;
- { Reset print record to default }
-
- PROCEDURE TStdPrintHandler.SetDefaultPrintInfo; OVERRIDE;
- { Create a PrintInfo record and initialize it to default values }
-
- PROCEDURE TStdPrintHandler.SetPrintExtent;
- { Sets the part of the print handler's view that is printed by this print handler, by
- calling the view's GetPrintExtent. }
-
- PROCEDURE TStdPrintHandler.SetMargins;
- { Install the desired page margins }
-
- PROCEDURE TStdPrintHandler.ValidatePrintRecord(VAR didChange: BOOLEAN);
- { Make certain that the current Print Record is compatible with the user's current
- printer choice; 'didChange' is set to TRUE iff the kind of printer changed }
-
- { Menu Commands }
-
- FUNCTION TStdPrintHandler.DoMenuCommand(aCmdNumber: CmdNumber): TCommand; OVERRIDE;
- { Handles 'show page breaks', among others }
-
- PROCEDURE TStdPrintHandler.DoSetupMenus; OVERRIDE;
- { Sets up menus for 'show page breaks' and company }
-
- { Finder Printing }
-
- FUNCTION TStdPrintHandler.SetupForFinder: BOOLEAN; OVERRIDE;
- { Sets up the print record for finder printing. If fFinderPageSetup is true, then
- PosePageSetupDialog is called. If fFinderJobDialog is true, then PoseJobDialog is
- called. Otherwise, prJobMerge is called to merge the job record from the }
-
- FUNCTION SetupPrintOne: BOOLEAN;
- { Sets up the print record for a "print one" type of operation, one where the entire
- document or view is printed and no job dialog takes place. Returns true if we
- should proceed. }
-
- { Screen Feedback }
-
- PROCEDURE TStdPrintHandler.DrawPrintFeedback(area: Rect); OVERRIDE;
- { Gateway to all screen feedback related to pagination issues }
-
- PROCEDURE TStdPrintHandler.DrawPageBreak(vhs: VHSelect;
- whichBreak: INTEGER;
- loc: VCoordinate;
- automatic: BOOLEAN); OVERRIDE;
- { Draws a page break on the screen. }
-
- PROCEDURE TStdPrintHandler.InvalPageFeedback;
- { Invalidates all page-related screen feedback }
-
- FUNCTION TStdPrintHandler.ShowsOnScreen: BOOLEAN;
- { Returns TRUE only if the printHandler has an fView which is in an open window. }
-
- { Dialogs relating to printing }
-
- FUNCTION TStdPrintHandler.PoseJobDialog: BOOLEAN;
- { Pose the 'Print Job' dialog }
-
- FUNCTION TStdPrintHandler.PosePageSetupDialog(VAR proceed: BOOLEAN;
- isUndoable: BOOLEAN): TCommand;
- { Undertake the 'Page Setup' dialog; return a command object to be performed if
- relevant }
-
- PROCEDURE TStdPrintHandler.PosePrintDialog;
- { Put up the 'Printing in Progress' dialog }
-
- PROCEDURE TStdPrintHandler.ShowDocBeingPrinted(entering: BOOLEAN);
- { Put up (or remove) a window whose title is the document's title, because the Print
- Manager gets the document title from the front window. }
-
- PROCEDURE TStdPrintHandler.BanishPrintDialog;
- { Get rid of the print dialog. }
-
- PROCEDURE TStdPrintHandler.DoPrintIdling;
- { Print job idle time handler. Handles events in the 'Print Dialogs' which give the
- user 'Cancel', and, in the case of printing from the Finder, 'Cancel All Printing.
- }
-
- PROCEDURE TStdPrintHandler.ChkPrintErr(VAR err: OSErr;
- VAR proceed: BOOLEAN;
- VAR ranOutOfSpace: BOOLEAN);
- { Checks for a MacPrint error, but only if 'proceed' is TRUE on entry; specially
- handles one particular error (sets return parameter 'ranOutOfSpace' if error code
- indicates disk-space problem while saving a spool file). }
-
- PROCEDURE TStdPrintHandler.PrintSpoolFile(anHPrint: Handle;
- VAR err: OSErr;
- VAR proceed: BOOLEAN);
- { If printing was spooled by the print-driver then this Method will be called
- to print the spooled image. }
-
- PROCEDURE TStdPrintHandler.GetDriverName(VAR driverName: Str255);
- { Get the name of the current printer driver. }
-
- { Debugging }
-
- PROCEDURE TStdPrintHandler.IdentifySoftware; OVERRIDE;
- { Shows the version of the Printing Unit being used; display is in
- the Debug window }
-
- PROCEDURE TStdPrintHandler.Fields(PROCEDURE
- DoToField(fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER)); OVERRIDE;
- { Used by the Inspector and the Debugger to display the contents of this classes
- fields. }
- END;
-
- {--------------------------------------------------------------------------------------------------}
- TPrintStyleChangeCommand = OBJECT (TCommand) { Used to allow changes made by the user in
- the 'Page Setup...' dialog to be
- undoable. }
-
- { Fields }
-
- fStdPrintHandler: TStdPrintHandler; { Associated print handler }
-
- fOldHPrint: Handle; { The old print record, before the change }
- fNewHPrint: Handle; { The new print record, after the change }
-
- { Initialization and Termination }
-
- PROCEDURE TPrintStyleChangeCommand.IPrintStyleChangeCommand(itsPrintHandler:
- TStdPrintHandler);
- { Initializes the print style change command, makes a copy of the old print handle
- and creates the new one. }
- PROCEDURE TPrintStyleChangeCommand.Free; OVERRIDE;
- { Disposes the old and new print handles. }
-
- { Command Execution }
-
- PROCEDURE TPrintStyleChangeCommand.DoIt; OVERRIDE;
- { Calls CheckPrinter, finding it changed will dispatch to views DoPrinterChanged
- method. }
-
- PROCEDURE TPrintStyleChangeCommand.UndoIt; OVERRIDE;
- { Copies the old print handle back and calls CheckPrinter which will in turn call the
- views DoPrinterChanged method. }
-
- PROCEDURE TPrintStyleChangeCommand.RedoIt; OVERRIDE;
- { Copies the new print handle back and calls CheckPrinter which will in turn call the
- views DoPrinterChanged method. }
-
- { Debugging }
- PROCEDURE TPrintStyleChangeCommand.Fields(PROCEDURE
- DoToField(fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER)); OVERRIDE;
- { Used by the Inspector and the Debugger to display the contents of this class's
- fields. }
-
- END;
-
- {--------------------------------------------------------------------------------------------------}
- TPrintCommand = OBJECT (TNoChangesCommand) { Returned in response to a printing
- request. Doesn't actually do the
- printing itself, but forwards to the
- appropriate handler. }
-
- fStdPrintHandler: TStdPrintHandler; { the associated print handler }
-
- PROCEDURE TPrintCommand.IPrintCommand(itsCmdNumber: CmdNumber;
- itsStdPrintHandler: TStdPrintHandler);
- { Initialize the PrintCommand procedurally }
-
- PROCEDURE TPrintCommand.DoIt; OVERRIDE;
- { Tell the print handler to print }
-
- PROCEDURE TPrintCommand.Fields(PROCEDURE
- DoToField(fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER)); OVERRIDE;
- { Used by the Inspector and the Debugger to display the contents of this class's
- fields. }
-
- END;
-
- VAR
- gBreaksPenState: PenState; { penState to used to draw page breaks }
- gCancelAllPrinting: BOOLEAN; { set to TRUE if during Finder Printing user
- selects “Cancel All” }
- gStdPageMargins: Rect; { "Standard" left, top, right, bottom page
- margins, in screen resolution - one inch
- all round by default }
- gFinderHPrint: Handle; { Used for finder printing, to do PrJobMerge
- when printing more than one document. }
-
- gJobPrintHandler: TStdPrintHandler; { The Print Handler in use during printing.
- }
-
- { Initialization }
-
- PROCEDURE InitUPrinting;
- { Call once, at application start-up time. You can interrogate global variable 'gCouldPrint'
- at any time to determine whether printing code is actually accessible }
-
- PROCEDURE InitPrinting;
- { Synonym for InitUPrinting. Left in for compatibility (2.0) }
-
- PROCEDURE IdleProcForTStdPrintHandler;
- { Procedure whose address is passed to the print job for calling as often as possible.
- Forwards to the DoPrintIdling method of the job's print handler. }
-
- {$ENDC}
-
- {$IFC NOT UsingIncludes}
- END.
- {$ENDC}
-